import requestUtil from '@/utils/requestEnc';
import CustOrderService from "@/api/order/CustOrderService";
export default {
    methods: {
        async getCustomerOrderDetail(Form,CTOInfo,ODKInfo){
            let {custSoNumber,batchNbr,custId} = CTOInfo,
                orderItemIds=CTOInfo.orderItemId,
                scopeInfos=[],
                keyarr = {};
            for(var key in Form){
                let item = Form[key];
                if(item.tableName){
                    let newkey = requestUtil.toHump(item.tableName)+'s';
                    if(!keyarr[newkey]){
                        keyarr[newkey]=1;
                        scopeInfos.push({
                            scope:newkey
                        });
                    }
                };
            }
            
            const result=await CustOrderService.qryCustomerOrderDetail({custSoNumber,batchNbr,orderItemIds,custId,scopeInfos});
            
            
            let odtals = {};
            for(var key in result.orderDetails[0]){
                let obj = result.orderDetails[0][key];
                if(key=='ordProdInsts'){
                    
                    for(var i=0;i<obj.length;i++){
                        let opt = obj[i];
                        odtals['procProdInstId'+opt.roleCd]=opt.rowId;
                        odtals['prodInstId'+opt.roleCd]=opt.prodInstId;
                    }
                }else if(key=='orderTasks'){
                    for(var i=0;i<obj.length;i++){
                        if(obj[i].taskReqDate&&!this.taskReqDate){
                            this.taskReqDate = this.$util.dateFormat(obj[i].taskReqDate,"yyyy-MM-dd");
                            
                            
                        }
                        if(ODKInfo.taskId == obj[i].taskId){
                            odtals['orderTaskId']=obj[i].orderTaskId;
                            this.orderTask = obj[i];
                            break;
                        }
                    }
                }
            };
            this.odtals=odtals;
            
        }
    }
}
